package random;

import bibliotekosis.Material;
import javax.swing.table.AbstractTableModel;
import java.util.List;

public class SearchTableModel extends AbstractTableModel
{
    private String[] columnNames = { "Name", "ISBN", "Year" };
    private Object[][] data = null;

    public SearchTableModel(List<Material> material)
    {   
        data = new Object[material.size()][3];
        
        int i = 0;
        for (Material m : material) {
            data[i++] = new Object[] {m.get("name"), m.get("ISBN"), m.get("year")};
        }
    }
    
    
    
    @Override
    public Class getColumnClass( int column ) 
    {
        return getValueAt(0, column).getClass();
    }
    @Override
    public int getColumnCount() 
    {
        return columnNames.length;
    }
    @Override
    public String getColumnName( int column ) 
    {
        return columnNames[column];
    }
    @Override
    public int getRowCount() 
    {
        return data.length;
    }
    @Override
    public Object getValueAt( int row, int column ) 
    {
        return data[row][column];
    }
    
    public void clear()
    {
        data = null;
    }

}